package bintree.heap.leetcode;

/**
 * 165. 比较版本号
 * @author haomin
 * @date 2022/03/23 21:16
 **/
public class Num165_CompareVersion {
    public int compareVersion(String version1, String version2) {
        String[] data1 = version1.split("\\.");
        String[] data2 = version2.split("\\.");

        for (int n = 0; n < Math.max(version1.length(),version2.length()); n++) {
            int i = (n < data1.length ? Integer.valueOf(data1[n]) : 0);
            int j = (n < data2.length ? Integer.valueOf(data2[n]) : 0);

            if(i < j){
                return -1;
            }else if(i > j){
                return 1;
            }
        }
        return 0;
    }
}